package edu.hawaii.ics314.ical.model;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.text.ParseException;


/**
 * Defines an event and can be used to write
 * to a buffer.
 * 
 * @author 
 *
 */
public class Event extends CalendarComponent {

	public Event(CalendarComponentInfo info) {
		super(info);
	}

	@Override
	public void readObject(BufferedReader in) throws IOException, ParseException {
		String curLine = null;
		do {
			curLine = peekNextLine(in);
			if(curLine.equals("BEGIN:VEVENT")) {
				in.readLine(); // Commit the read and ignore line.
			} else if(curLine.equals("END:VEVENT")) {
				in.readLine(); // Commit the read and return control to caller.
				break;
			} else {
				readProperties(in, null); // Do NOT commit the read. Begin parsing standard properties.
			}
		} while(curLine != null);
	}

	@Override
	public void writeObject(BufferedWriter out) throws IOException {
		final String CRLF = "\r\n";
		out.write("BEGIN:VEVENT");
		out.write(CRLF);
		writeProperties(out);
		out.write("END:VEVENT");
	}

}
